package com.ruoyi.web.core.utils;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

/**
 * <pre>
 *
 * </pre>
 *
 * @author zhangli
 * @since 2023/7/29
 */
@Slf4j
@Component
public class DingTalkUtil {

    @Autowired
    private HttpClient httpClient;

    @Value("${dingtalk.webhook}")
    private String webhook;


    public void sendNotify(String content){
        Map<String,Object> json=new HashMap();
        Map<String,Object> text=new HashMap();
        json.put("msgtype","text");
        text.put("content","红包通知："+content);
        json.put("text",text);

        Map<String,Boolean> at=new HashMap();
        at.put("isAtAll",true);
        json.put("at",at);

        httpClient.doPost(webhook, (JSONObject) JSONObject.toJSON(json));

        log.info("send dingidng notify: {}",text);
    }

}
